package org.esky;

/**
 * 写一段程序，实现将F盘下的所有.java程序拷贝复制到E盘
 */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class T3 {
	private static InputStream is;
	private static OutputStream os;

	public static void main(String[] args) {
		FileCut("F:/", "E:/");
	}

	public static void FileCut(String oldPath, String newPath) {
		File dir = new File(oldPath);
		File[] files = dir.listFiles();
		for (File file : files) {
			String FileName = file.getName();
			int index = FileName.indexOf(".");
			if (index != -1) {
				String FileName1 = FileName.substring(0, index);
				String HouZhui = FileName.substring(index);
				if (HouZhui.equals(".java")) {
					try {
						is = new FileInputStream(oldPath + FileName1 + ".java");
						os = new FileOutputStream(newPath + FileName1 + ".java");
						byte[] buffer = new byte[8192];
						int length;
						while ((length = is.read(buffer)) != -1) {
							os.write(buffer, 0, length);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}

		}
	}
}
